<!--制程巡检记录:processInspectionRecord-->
<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      v-model="form"
      :data="data"
      :page.sync="page"
      :search.sync="query"
      :permission="permissionList"
      :before-open="beforeOpen"
      ref="crud"
      @row-update="rowUpdate"
      @row-save="rowSave"
      @row-del="rowDel"
      @selection-change="selectionChange"
      @search-change="searchChange"
      @search-reset="searchReset"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
    >
      <template slot="menuLeft">
        <!-- <el-button type="primary" size="small" icon="el-icon-plus" @click="handleAdd">新增报检</el-button>
        <el-button type="danger" size="small" icon="el-icon-back" @click="handleDelete">撤销报检</el-button> -->
        <el-button type="success" size="small" icon="el-icon-download" v-if="permission.ipqcInspectionRecords_export" @click="handleExport">导出</el-button>
        <el-button type="warning" size="small" icon="el-icon-check" v-if="permission.ipqcInspectionRecords_revoke" @click="handleSecondTimeInspection">二次检</el-button>
      </template>
      <template slot-scope="{ row }" slot="menu">
        <el-button type="text" size="small" icon="el-icon-view" @click="handleEdit(row, 'view')">详情</el-button>
        <el-button type="text" size="small" icon="el-icon-edit" @click="handleEdit(row, 'edit')">编辑</el-button>
        <el-button size="small" type="text" v-if="permission.ipqcInspectionRecords_reportForms" @click="viewQcExamineReport(row)">检验报表</el-button>
        <el-button size="small" type="text" v-if="permission.ipqcInspectionRecords_report" @click="viewApaasExamineReport(row)">检验报告</el-button>
      </template>
      <template slot="menuRight">
        <user-table-config :option="option" @confirm="(val) => handleSetUserConfig(val, pageCode)"></user-table-config>
      </template>
    </avue-crud>
    <!-- 新增首件检验 -->
    <el-dialog append-to-body :close-on-click-modal="false" title="新增首件检验" :visible.sync="addDialog" :before-close="addClose">
      <avue-form v-if="addDialog" ref="addForm" v-model="addForm" :option="addOption"></avue-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" @click="addInapection"><i class="el-icon-circle-plus-outline"></i><span>提 交</span></el-button>
        <el-button size="small" @click="addDialog = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>
      </span>
    </el-dialog>
    <!-- 撤销检验 -->
    <el-dialog append-to-body :close-on-click-modal="false" title="撤销检验" :visible.sync="revokeDialog" :before-close="revokeDialogClose">
      <avue-form ref="revokeForm" v-if="revokeDialog" v-model="revokeForm" :option="revokeOption"></avue-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" @click="revokeSubmit"><i class="el-icon-circle-plus-outline"></i><span>提 交</span></el-button>
        <el-button size="small" @click="addAbnormalDialog = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>
      </span>
    </el-dialog>

    <!-- 详情/编辑 -->
    <el-dialog
      :fullscreen="true"
      custom-class="processInspectionRecord"
      append-to-body
      :close-on-click-modal="false"
      :title="firstInspectionRecordDialogTitle"
      :visible.sync="handleDialog"
      :before-close="handleClose"
    >
      <!-- 基本信息 -->
      <div class="titleIcon">
        <i class="el-icon-vertical-bar avue-group__icon"></i>
        <div class="name">基本信息</div>
      </div>
      <el-divider></el-divider>
      <avue-form ref="basicInfoForm" v-if="handleDialog" v-model="basicInfoForm" :option="basicInfoOption"></avue-form>

      <!-- 检验结果记录 -->
      <div class="titleIcon flex">
        <div class="title">
          <i class="el-icon-vertical-bar avue-group__icon"></i>
          <div class="name">检验结果记录</div>
        </div>
        <el-button size="small" type="primary" @click="queryHistroyCheckRecords">历史检验记录查询</el-button>
      </div>
      <el-divider></el-divider>
      <avue-form v-if="handleDialog" ref="inspectionResultsRecordForm" v-model="inspectionResultsRecordForm" :option="inspectionResultsRecordOption">
        <template slot="attachments">
          <el-upload
            class="upload-demo"
            action="/api/blade-resource/oss/endpoint/put-file-attach"
            :disabled="isView"
            :on-preview="handlePreview"
            :headers="headersObj"
            :on-success="inspectionUploadSuccess"
            :file-list="inspectionPictureList"
            :on-remove="inspectionRemoveFile"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <!-- <i class="el-icon-plus"></i>
            <div slot="tip" class="el-upload__tip">只能上传png/jpeg/jpg文件</div> -->
          </el-upload>
          <!-- <div v-if="dialogTitle === '详情' && JSON.stringify(form.CERT) != '[]'">
            <div>{{ form.CERTNAME }}</div>
            <el-button type="text" icon="el-icon-download" size="small" @click="handleDownload(form.CERT)">下载</el-button>
          </div> -->
        </template>
      </avue-form>

      <!-- 异常记录 -->
      <!-- Test 20240116 22:10 测试验证合并请求云效管控 -->
      <div v-if="inspectionResultsRecordForm.examineResult === 'NG'" class="titleIcon">
        <i class="el-icon-vertical-bar avue-group__icon"></i>
        <div class="name">异常记录</div>
      </div>
      <el-divider></el-divider>
      <avue-crud
        v-if="handleDialog && inspectionResultsRecordForm.examineResult === 'NG'"
        ref="bnormalRecordCrud"
        :option="abnormalRecordOption"
        :data="abnormalRecordData"
        @selection-change="selectionProductChange"
      >
        <template v-if="!isView" slot="menuLeft">
          <el-button type="primary" size="small" icon="el-icon-plus" @click="handleAddProduct">新增异常记录</el-button>
        </template>
        <template slot-scope="{ row, index }" slot="menu">
          <el-button icon="el-icon-view" size="small" type="text" @click="abnormalRecordRowUpdate(row, 'view')">详情</el-button>
          <el-button v-if="!isView" icon="el-icon-edit" size="small" type="text" @click="abnormalRecordRowUpdate(row, 'edit')">编辑</el-button>
          <el-button v-if="!isView" icon="el-icon-delete" size="small" type="text" @click="abnormalRecordDel(index)">删除</el-button>
        </template>
      </avue-crud>

      <span slot="footer" class="dialog-footer">
        <!-- <el-button v-if="!isView" size="small" type="success" @click="handleSubmit(4)"><i class="el-icon-circle-plus-outline"></i><span>保存草稿</span></el-button> -->
        <el-button v-if="!isView" size="small" type="primary" @click="handleSubmit(2)"><i class="el-icon-circle-plus-outline"></i><span>提 交</span></el-button>
        <el-button size="small" @click="handleDialog = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>
      </span>
    </el-dialog>
    <!-- 新增异常记录 -->
    <el-dialog append-to-body :close-on-click-modal="false" :title="addAbnormalDialogTitle" :visible.sync="addAbnormalDialog" :before-close="addAbnormalDialogClose">
      <avue-form ref="abnormalForm" v-if="addAbnormalDialog" v-model="abnormalForm" :option="abnormalOption">
        <template slot="attachments">
          <!-- <div v-if="dialogTitle != '详情' && form.CERT"> -->
          <el-upload
            class="upload-demo"
            action="/api/blade-resource/oss/endpoint/put-file-attach"
            list-type="picture-card"
            accept=".png,.jpeg,.jpg"
            :on-preview="handlePreview"
            :headers="headersObj"
            :before-upload="pictureUploadBefore"
            :on-success="pictureUploadSuccess"
            :file-list="pictureList"
            :on-remove="pictureRemoveFile"
          >
            <i class="el-icon-plus"></i>
            <div slot="tip" class="el-upload__tip">只能上传png/jpeg/jpg文件</div>
          </el-upload>
          <!-- </div> -->
          <div v-if="dialogTitle === '详情' && JSON.stringify(form.CERT) != '[]'">
            <div>{{ form.CERTNAME }}</div>
            <el-button type="text" icon="el-icon-download" size="small" @click="handleDownload(form.CERT)">下载</el-button>
          </div>
        </template>
      </avue-form>
      <span slot="footer" class="dialog-footer">
        <el-button v-if="addAbnormalDialogTitle === '新增异常记录'" size="small" type="primary" @click="abnormalSubmit('add')">
          <i class="el-icon-circle-plus-outline"></i><span>保 存</span></el-button
        >
        <el-button v-if="addAbnormalDialogTitle === '编辑异常记录'" size="small" type="primary" @click="abnormalSubmit('edit')">
          <i class="el-icon-circle-check"></i><span>修 改</span></el-button
        >
        <el-button size="small" @click="addAbnormalDialog = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>
      </span>
    </el-dialog>
    <!--公用模态弹框-->
    <common-modal-template ref="commonModalTemplate" :option="tableOption" @getSelectedRows="getSelectedRows"> </common-modal-template>
    <!-- <export-excel
      :visible="exprotVisible"
      :option="option"
      :page="page"
      :data="exportData"
      name="excel导入配置"
      :loading="btnLoading"
      @selectData="handleSelectData"
      @close="exportHandleClose"
    ></export-excel> -->

    <export-comp
      ref="exportComp"
      page-api-url="mes-product/qms-inspection-document/page?statusStr=2,3,5,6&documentType=IPQC"
      :option="option"
      :page="page"
      :query="exportParams"
      file-name="制程巡检记录"
    ></export-comp>
    <el-dialog
      ref="dialog"
      title="查看PDF"
      append-to-body
      :visible.sync="showEsopDialog"
      :full-screen="fullScreen"
      :class="[fullScreen ? 'fullscreen' : 'no_fullScreen']"
      :close-on-click-modal="false"
      @close="fullScreen = false"
    >
      <iframe ref="pdf" :src="pdfUrl" width="100%" :height="iframeHeight"></iframe>
      <div slot="title" class="dialog-title">
        <span class="title">查看PDF</span>
        <span class="el-dialog__close fullscreen-icon" @click="fullScreen = !fullScreen">
          <i class="el-icon-full-screen"></i>
        </span>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="showEsopDialog = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>
      </span>
    </el-dialog>
    <!--检验报告-->
    <el-dialog
      v-if="apaasInspectionReportDialog"
      fullscreen
      append-to-body
      :modal-append-to-body="true"
      :close-on-click-modal="false"
      title="检验报告"
      :visible.sync="apaasInspectionReportDialog"
    >
      <view-apaas-inspection-report :operateBtn="false" v-if="apaasInspectionReportDialog" ref="apaasReport"></view-apaas-inspection-report>
    </el-dialog>
    <doc-preview :url="fileUrl" :visiable.sync="previewVisible" :file-type="fileType"></doc-preview>
  </basic-container>
</template>
<script>
import { mapGetters } from 'vuex';
import userTableConfig from '@/components/user-table-config/index.vue';
import userConfig from '@/mixins/userConfig';
import exportComp from '@/components/export-comp';
import commonModalTemplate from '@/components/common-modal-template/common-modal-template';
import { filterEmptyValues } from '@/util/util';
import {
  getList,
  add,
  getWorkOrderDetail,
  getLineList,
  getDetail,
  getMainTypeList,
  getSubTypeList,
  revoke,
  handle,
  secondTimeInspection
} from '@/api/quality/processInspectionRecord';
import website from '@/config/website';
import { Base64 } from 'js-base64';
import { getToken } from '@/util/auth';
import exportExcel from '@/components/export-excel';
import DocPreview from '@/components/filePreview/docPreview';
import { downLoad } from '@/api/resource/attach';
import viewApaasInspectionReport from '@/views/designer/preview';
export default {
  name: 'qualityProcessInspectionRecord',
  components: {
    userTableConfig,
    commonModalTemplate,
    exportExcel,
    exportComp,
    DocPreview,
    viewApaasInspectionReport
  },
  mixins: [userConfig()],
  data() {
    return {
      form: {},
      query: {},
      tableOption: {},
      modalName: '',
      fileType: '',
      fileUrl: '',
      pdfUrl: '',
      previewVisible: false,
      showEsopDialog: false,
      apaasInspectionReportDialog: false,
      fullScreen: '',
      loading: false,
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      exportParams: {},
      data: [],
      option: {
        height: 'calc(100vh - 408px)',
        calcHeight: 30,
        selectionList: [],
        tip: false,
        searchShow: true,
        searchMenuSpan: 6,
        border: true,
        index: true,
        viewBtn: false,
        editBtn: false,
        delBtn: false,
        addBtn: false,
        indexLabel: '序号',
        columnBtn: false,
        selection: true,
        menuWidth: 260,
        column: [
          {
            label: '检验单号',
            prop: 'documentNo',
            searchOrder: 7,
            type: 'search',
            search: true,
            appendClick: () => {
              this.openCommon('documentNo');
            }
          },
          {
            label: '巡检类型',
            prop: 'documentSubType',
            width: 100,
            type: 'select',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            },
            dicUrl: '/api/blade-system/dict/dictionary?code=ipqc_type'
          },
          {
            label: '车间',
            prop: 'workshopId',
            width: 100,
            filterable: true,
            type: 'select',
            searchOrder: 5,
            search: true,
            dicUrl: '/api/mes-admin/workshop/key-value',
            props: {
              label: 'workshopName',
              value: 'workshopId'
            }
          },
          {
            label: '产线',
            prop: 'lineId',
            width: 100,
            type: 'select',
            filterable: true,
            searchOrder: 2,
            search: true,
            dicData: []
          },
          {
            label: '巡检时段',
            prop: 'ipqcTimeframe'
          },
          {
            label: '生产工单',
            prop: 'sourceNo',
            type: 'search',
            searchOrder: 3,
            search: true,
            appendClick: () => {
              this.openCommon('sourceNo');
            }
          },
          {
            label: '产品编码',
            prop: 'partNo',
            type: 'search',
            search: true,
            searchOrder: 1,
            appendClick: () => {
              this.openCommon('partNo');
            }
          },
          {
            label: '产品名称',
            prop: 'partName'
          },
          {
            label: '产品型号',
            prop: 'partModel',
            width: 100
          },
          { label: '检验结果', prop: 'examineResult' },
          {
            label: '是否加急',
            prop: 'isUrgent',
            width: 80,
            search: true,
            searchOrder: 4,
            type: 'select',
            dicData: [
              { label: '是', value: true },
              { label: '否', value: false }
            ]
          },
          {
            label: '检验状态',
            prop: 'status',
            width: 80,
            type: 'select',
            dicData: [
              { label: '待检验', value: 1 },
              { label: '已检验', value: 2 },
              { label: '检验完成', value: 3 },
              { label: '草稿', value: 4 },
              { label: '超期关闭', value: 5 },
              { label: '已撤销', value: 6 },
              { label: '已撤销', value: 6 }
            ]
          },
          {
            label: '报检时间',
            prop: 'createTime'
          },
          {
            label: '检验时间',
            prop: 'examineDate',
            search: true,
            searchSpan: 6,
            type: 'datetime',
            searchType: 'datetimerange',
            format: 'yyyy-MM-dd HH:mm:ss',
            valueFormat: 'yyyy-MM-dd HH:mm:ss',
            startPlaceholder: '开始日期',
            endPlaceholder: '结束日期'
          },
          {
            label: '检验人员',
            prop: 'examineByName'
          },
          {
            label: '撤销原因',
            prop: 'revocation'
          }
        ]
      },
      addDialog: false,
      addForm: {},
      addOption: {
        submitBtn: false,
        emptyBtn: false,
        labelWidth: 150,
        column: [
          {
            label: '生产工单',
            prop: 'sourceNo',
            type: 'search',
            rules: [
              {
                required: true,
                message: '请选择生产工单',
                trigger: 'blur'
              }
            ],
            appendClick: () => {
              this.openWorkOrderCommonModal();
            }
          },
          {
            label: '工单数量',
            prop: 'workOrderQuantity',
            disabled: true
          },
          {
            label: '客户名称',
            prop: 'partnerName',
            disabled: true
          },
          {
            label: '物料编码',
            prop: 'partNo',
            disabled: true
          },
          {
            label: '物料名称',
            prop: 'partName',
            disabled: true
          },
          {
            label: '产品型号',
            prop: 'partModel',
            disabled: true
          },
          {
            label: '生产产线',
            prop: 'lineId',
            type: 'select',
            dicData: [],
            rules: [
              {
                required: true,
                message: '请选择生产产线',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '检验分类',
            prop: 'sourceType',
            type: 'select',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            },
            dicUrl: '/api/blade-system/dict/dictionary?code=inspect_sub_type'
          },
          {
            label: '检验说明',
            prop: 'examineDescription'
          },
          {
            label: '是否加急',
            prop: 'isReplacement',
            type: 'switch',
            value: false,
            dicData: [
              {
                label: '否',
                value: false
              },
              {
                label: '是',
                value: true
              }
            ]
          }
        ]
      },
      handleDialog: false,
      revokeDialog: false,
      revokeForm: {},
      revokeOption: {
        submitBtn: false,
        emptyBtn: false,
        labelWidth: 150,
        group: [
          {
            label: '撤销原因',
            prop: 'revoke',
            arrow: false,
            icon: 'el-icon-vertical-bar',
            column: [
              {
                label: '撤销原因',
                prop: 'revocation',
                type: 'textarea',
                span: 24,
                maxRows: 3,
                minRows: 3,
                rules: [
                  {
                    required: true,
                    message: '请选择撤销原因',
                    trigger: 'blur'
                  }
                ]
              }
            ]
          },
          {
            label: '基本信息',
            prop: 'basicInfo',
            arrow: false,
            icon: 'el-icon-vertical-bar',
            column: [
              {
                label: '检验单号',
                prop: 'documentNo',
                disabled: true
              },
              {
                label: '检验分类',
                prop: 'sourceType',
                type: 'select',
                props: {
                  label: 'dictValue',
                  value: 'dictKey'
                },
                dicUrl: '/api/blade-system/dict/dictionary?code=inspect_sub_type',
                disabled: true
              },
              {
                label: '产线',
                prop: 'lineName',
                disabled: true
              },
              {
                label: '物料编码',
                prop: 'partNo',
                disabled: true
              },
              {
                label: '物料名称',
                prop: 'partName',
                disabled: true
              },
              {
                label: '是否加急',
                prop: 'isUrgent',
                type: 'switch',
                value: false,
                dicData: [
                  {
                    label: '否',
                    value: false
                  },
                  {
                    label: '是',
                    value: true
                  }
                ],
                disabled: true
              },
              {
                label: '客户名称',
                prop: 'partnerName',
                disabled: true
              },
              {
                label: '工单号',
                prop: 'sourceNo',
                disabled: true
              }
            ]
          }
        ]
      },
      basicInfoForm: {},
      basicInfoOption: {
        submitBtn: false,
        emptyBtn: false,
        labelWidth: 150,
        column: [
          {
            label: '巡检类型',
            prop: 'documentSubType',
            type: 'select',
            span: 8,
            props: {
              label: 'dictValue',
              value: 'dictKey'
            },
            disabled: true,
            dicUrl: '/api/blade-system/dict/dictionary?code=ipqc_type'
          },
          {
            label: '车间',
            prop: 'workshopId',
            filterable: true,
            disabled: true,
            type: 'select',
            span: 8,
            searchOrder: 5,
            search: true,
            dicUrl: '/api/mes-admin/workshop/key-value',
            props: {
              label: 'workshopName',
              value: 'workshopId'
            }
          },
          {
            label: '产线',
            disabled: true,
            span: 8,
            prop: 'lineName'
          },
          {
            label: '生产工单',
            prop: 'sourceNo',
            span: 8,
            disabled: true
          },
          {
            label: '工单数量',
            prop: 'workOrderQuantity',
            span: 8,
            disabled: true
          },
          {
            label: '产品型号',
            prop: 'partModel',
            span: 8,
            disabled: true
          },
          {
            label: '物料编码',
            prop: 'partNo',
            span: 8,
            disabled: true
          },
          {
            label: '物料名称',
            prop: 'partName',
            span: 8,
            disabled: true
          },
          {
            label: '是否加急',
            prop: 'isUrgent',
            span: 8,
            type: 'select',
            dicData: [
              {
                label: '否',
                value: false
              },
              {
                label: '是',
                value: true
              }
            ],
            disabled: true
          },

          {
            label: '巡检时段',
            prop: 'ipqcTimeframe',
            span: 8,
            disabled: true
          },
          {
            label: '报检时间',
            prop: 'createTime',
            span: 8,
            disabled: true
          },

          {
            label: '检验人',
            prop: 'examineByName',
            type: 'search',
            span: 8,
            disabled: true,
            appendClick: () => {
              // 编辑时允许弹窗修改
              if (this.openHandleDialogType === 'edit') {
                this.openUserCommonModal();
              }
            }
          }
        ]
      },
      inspectionResultsRecordForm: {},
      inspectionResultsRecordOption: {
        submitBtn: false,
        emptyBtn: false,
        labelWidth: 150,
        column: [
          {
            label: '检验结果',
            prop: 'examineResult',
            span: 24,
            disabled: true,
            row: true,
            rules: [
              {
                required: true,
                message: '请输入 检验结果',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '上传检验报告',
            prop: 'attachments',
            type: 'upload',
            span: 24,
            loadText: '图片上传中，请稍等',
            propsHttp: {
              url: 'link',
              name: 'attachId',
              res: 'data'
            },
            listType: 'picture-card',
            accept: 'image/png, image/jpeg, image/jpg',
            tip: '只能上传png/jpeg/jpg文件',
            action: '/api/blade-resource/oss/endpoint/put-file-attach',
            rules: [
              {
                required: true,
                message: '请上传检验报告',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '备注',
            prop: 'remark',
            type: 'textarea',
            span: 24,
            maxRows: 3,
            minRows: 3
          }
        ]
      },
      abnormalDialogTitle: '新增异常记录',
      abnormalRecordData: [],
      abnormalRecordOption: {
        height: '300',
        calcHeight: 30,
        tip: false,
        border: true,
        index: true,
        indexLabel: '序号',
        selection: true,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        viewBtn: false,
        menu: true,
        refreshBtn: false,
        columnBtn: false,
        column: [
          {
            label: '不良现象',
            prop: 'ngFailureName'
          },
          {
            label: '不良原因（大类）',
            prop: 'ngMainCauseName'
          },
          {
            label: '不良原因（小类）',
            prop: 'ngSubCauseName'
          },
          {
            label: '不良说明',
            prop: 'faultDescription'
          },
          {
            label: '改善措施',
            prop: 'improvementMeasure'
          },
          {
            label: '备注',
            prop: 'remark'
          },
          {
            label: '附件',
            prop: 'attachmentName',
            overHidden: true
          }
        ]
      },
      addAbnormalDialogTitle: '新增异常记录',
      addAbnormalDialog: false,
      abnormalForm: {},
      abnormalOption: {
        submitBtn: false,
        emptyBtn: false,
        labelWidth: 150,
        column: [
          {
            label: '不良代码',
            prop: 'failureCode',
            type: 'search',
            appendClick: () => {
              this.openFailureCommonModal();
            },
            rules: [
              {
                required: true,
                message: '请选择不良代码',
                trigger: 'blur'
              }
            ],
            disabled: true
          },
          {
            label: '不良原因（大类）',
            prop: 'mainType',
            type: 'select',
            dicData: [],
            rules: [
              {
                required: true,
                message: '请选择不良原因（大类）',
                trigger: 'blur'
              }
            ],
            change: (val) => {
              if (val.value) {
                this.getSubTypeList(val.value);
              } else {
                const column = this.findObject(this.abnormalOption.column, 'subType');
                column.dicData = [];
                this.abnormalForm.subName = '';
              }
            }
          },
          {
            label: '不良原因（小类）',
            prop: 'subType',
            type: 'select',
            multiple: true,
            dicData: []
          },
          {
            label: '不良描述',
            prop: 'faultDescription',
            type: 'textarea',
            span: 24,
            maxRows: 3,
            minRows: 3
          },
          {
            label: '改善措施',
            prop: 'improvementMeasure',
            type: 'textarea',
            span: 24,
            maxRows: 3,
            minRows: 3,
            rules: [
              {
                required: true,
                message: '请选择改善措施',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '备注',
            prop: 'remark',
            type: 'textarea',
            span: 24,
            maxRows: 3,
            minRows: 3
          },
          {
            label: '附件',
            prop: 'attachments',
            type: 'upload',
            span: 16,
            loadText: '图片上传中，请稍等',
            propsHttp: {
              url: 'link',
              name: 'attachId',
              res: 'data'
            },
            listType: 'picture-card',
            accept: 'image/png, image/jpeg, image/jpg',
            tip: '只能上传png/jpeg/jpg文件',
            action: '/api/blade-resource/oss/endpoint/put-file-attach'
          }
        ]
      },

      lineList: [],
      documentNo: '',
      attachmentsList: [],
      inspectionPictureList: [],
      pictureList: [],
      abnormalRecordIndex: 0,
      mainTypeList: [],
      subTypeList: [],
      openHandleDialogType: 'edit',
      exprotVisible: false,
      btnLoading: false,
      exportData: []
    };
  },
  created() {
    let queryParams = this.$route.query;
    if (queryParams && queryParams.partNo) {
      this.query.partNo = decodeURIComponent(queryParams.partNo);
    }
  },

  mounted() {
    if (this.$route.query.lineId) {
      this.$set(this.query, 'lineId', this.$route.query.lineId);
    }
    if (this.$route.query.examineDate) {
      const curDate = `${this.$route.query.examineDate}-01 00:00:00`;
      let examineStartTime = this.$moment(curDate).format('YYYY-MM-DD HH:mm:ss');
      let daysInMonth = this.$moment(this.$route.query.examineDate, 'YYYY-MM').daysInMonth();
      let examineEndTime = this.$moment(examineStartTime)
        .add(daysInMonth - 1, 'days')
        .format('YYYY-MM-DD 23:59:59');
      this.$set(this.query, 'examineDate', [examineStartTime, examineEndTime]);
    }
    this.onLoad(this.page);
    this.$nextTick(() => {
      this.$structuralSplit();
    });
    const column = this.findObject(this.abnormalOption.column, 'mainType');
    getMainTypeList().then(
      (res) => {
        this.mainTypeList = this._get(res, 'data.data', []);
        column.dicData = this._get(res, 'data.data', []);
        column.dicData = this._map(column.dicData, (item) => {
          return {
            label: item.name,
            value: item.id
          };
        });
      },
      (error) => {
        column.dicData = [];
      }
    );
    this.getAllLine();
  },
  computed: {
    ...mapGetters(['permission']),
    permissionList() {
      return {
        delBtn: this.vaildData(this.permission.plan_config_del, false)
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(',');
    },
    headersObj() {
      let header = { Authorization: `Basic ${Base64.encode(`${website.clientId}:${website.clientSecret}`)}` };
      header['Blade-Auth'] = 'bearer ' + getToken();
      return header;
    },
    isView() {
      return this.openHandleDialogType == 'view';
    },
    firstInspectionRecordDialogTitle() {
      return this.isView ? '制程巡检记录详情' : '制程巡检记录编辑';
    },
    iframeHeight() {
      const docHeight = document.documentElement.clientHeight;
      const iframeHeight = docHeight - 188 + 'px';
      return this.fullScreen ? iframeHeight : '600px';
    }
  },
  methods: {
    async viewQcExamineReport(row) {
      window.open(`${this.website.reportUrl}/preview?_u=blade-IPQC巡检记录报表模板.ureport.xml&qcId=${row.id}`);
    },
    viewApaasExamineReport(row) {
      if (!row.examineContent) {
        this.$message({
          type: 'warning',
          message: '检验报告信息不存在!'
        });
        return;
      }
      let examineContent = JSON.parse(row.examineContent || '{}');
      this.apaasInspectionReportDialog = true;
      this.$nextTick(() => {
        this.$refs.apaasReport.setDataJson(examineContent);
      });
    },
    rowSave(row, done, loading) {},
    rowUpdate(row, index, done, loading) {},
    rowDel(row) {
      this.$confirm('确定将选择数据删除?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          // ajax
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
        });
    },
    handleAdd() {
      this.addDialog = true;
    },
    handleEdit(row, type) {
      this.handleDialog = true;
      this.openHandleDialogType = type;
      if (type === 'edit') {
        this.$nextTick(() => {
          this.$refs.basicInfoForm.allDisabled = false;
          this.$refs.inspectionResultsRecordForm.allDisabled = false;
        });
        // this.abnormalRecordOption.menu = true;
      } else {
        this.$nextTick(() => {
          this.$refs.basicInfoForm.allDisabled = true;
          this.$refs.inspectionResultsRecordForm.allDisabled = true;
        });
        // this.abnormalRecordOption.menu = false;
      }
      this.inspectionPictureList = [];
      this.inspectionResultsRecordForm.attachments = [];
      getDetail(row.id).then((res) => {
        this.basicInfoForm = this._get(res, 'data.data', {});
        this.basicInfoForm.examineBy = this.basicInfoForm.examineBy ? this.basicInfoForm.examineBy : JSON.parse(localStorage.getItem('saber-userInfo')).content.user_id;
        this.basicInfoForm.examineByName = this.basicInfoForm.examineByName
          ? this.basicInfoForm.examineByName
          : JSON.parse(localStorage.getItem('saber-userInfo')).content.user_name;
        let attachments = this._get(res, 'data.data.qmsInspectionAttachmentList', []);
        if (attachments != null) {
          this._forEach(attachments, (item) => {
            this.inspectionResultsRecordForm.attachments.push({
              attachmentId: item.attachmentId,
              link: item.link,
              attachmentName: item.attachmentName,
              attachmentType: 'INSPECTION'
            });
            this.inspectionPictureList.push({
              name: item.attachmentName,
              url: item.link
            });
          });
          console.log(this.inspectionResultsRecordForm.attachments);
        }
        this.inspectionResultsRecordForm.examineResult = this._get(res, 'data.data.examineResult', '');
        this.inspectionResultsRecordForm.remark = this._get(res, 'data.data.remark', '');
        this.abnormalRecordData = this._get(res, 'data.data.qmsInspectionExceptionVoList', []);
        if (this.abnormalRecordData != null) {
          this._forEach(this.abnormalRecordData, (item) => {
            (item.qmsInspectionExceptionDetailList = this._map(this._cloneDeep(item.qmsInspectionExceptionDetailList), (itemObj) => {
              let obj = {};
              if (itemObj.dictType === 'FAILURE') {
                obj.dictType = 'FAILURE';
                obj.dictId = itemObj.dictId;
                obj.dictCode = itemObj.dictCode;
                obj.dictName = itemObj.dictName;
                obj.remark = itemObj.remark;
              } else {
                if (itemObj.subType === 'MAIN') {
                  obj.dictType = 'CAUSE';
                  obj.subType = 'MAIN';
                  obj.dictId = itemObj.dictId;
                  obj.dictCode = itemObj.dictCode;
                  obj.dictName = itemObj.dictName;
                  obj.remark = itemObj.remark;
                } else {
                  obj.dictType = 'CAUSE';
                  obj.subType = 'SUB';
                  obj.dictId = itemObj.dictId;
                  obj.dictCode = itemObj.dictCode;
                  obj.dictName = itemObj.dictName;
                  obj.remark = itemObj.remark;
                }
              }
              return obj;
            })),
              (item.qmsInspectionAttachmentList = this._map(item.qmsInspectionAttachmentList, (attachmentItem) => {
                return {
                  attachmentId: attachmentItem.attachmentId,
                  link: attachmentItem.link,
                  attachmentName: attachmentItem.attachmentName,
                  attachmentType: 'INSPECTION'
                };
              }));
          });
        }
        this.abnormalRecordData.forEach((item) => {
          item.attachmentName = item.qmsInspectionAttachmentList.map((list) => list.attachmentName).join(',');
        });
        console.log(this.abnormalRecordData);
      });
    },
    handleClose(done) {
      this.$refs.inspectionResultsRecordForm.resetFields();
      this.inspectionResultsRecordForm = {};
      done();
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.revokeDialog = true;
      this.revokeForm = this.selectionList[0];
    },
    revokeSubmit() {
      this.$refs.revokeForm.validate((valid, done) => {
        if (valid) {
          const data = { id: this.revokeForm.id, revocation: this.revokeForm.revocation };
          revoke(data).then((res) => {
            this.$message.success(res.data.msg);
            this.revokeDialog = false;
            this.onLoad(this.page);
          });
        }
      });
    },
    beforeOpen(done, type) {},
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      this.onLoad(this.page);
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      this.onLoad(this.page);
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    onLoad(page, params = {}) {
      this.loading = true;
      params.descs = 'update_time';
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query, { documentType: 'IPQC' })).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    },
    handleAddProduct() {
      this.addAbnormalDialog = true;
      this.addAbnormalDialogTitle = '新增异常记录';
    },
    getSubTypeList(id) {
      const column = this.findObject(this.abnormalOption.column, 'subType');
      getSubTypeList(id).then(
        (res) => {
          this.subTypeList = this._get(res, 'data.data.subList', []);
          column.dicData = this._get(res, 'data.data.subList', []);
          column.dicData = this._map(column.dicData, (item) => {
            return {
              label: item.name,
              value: item.id
            };
          });
        },
        (error) => {
          column.dicData = [];
        }
      );
    },
    getAllLine() {
      const lineId = this.findObject(this.addOption.column, 'lineId');
      const optionLineId = this.findObject(this.option.column, 'lineId');
      getLineList().then(
        (res) => {
          this.lineList = this._get(res, 'data.data', []);
          lineId.dicData = this._get(res, 'data.data', []);
          lineId.dicData = this._map(lineId.dicData, (item) => {
            return {
              label: item.name,
              value: item.id
            };
          });
          optionLineId.dicData = lineId.dicData;
        },
        (error) => {
          lineId.dicData = [];
          optionLineId.dicData = [];
        }
      );
    },
    openWorkOrderCommonModal() {
      this.$refs.commonModalTemplate.showModal();
      this.modalName = 'workOrderModal';
      this.tableOption = {
        modalTitle: '选择工单号（双击进行选择）',
        url: '/api/mes-product/work-order/page?workOrderStatus=2,3',
        isPage: true,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '生产订单',
            prop: 'productionOrderNo',
            search: true
          },
          {
            label: '生产工单',
            prop: 'orderNo',
            search: true
          },
          {
            label: '工单类型',
            prop: 'orderType',
            type: 'select',
            dicUrl: '/api/blade-system/dict/dictionary?code=order_type',
            props: {
              label: 'dictValue',
              value: 'dictKey'
            }
          },
          {
            label: '工单数量',
            prop: 'planQuantity'
          },
          {
            label: '产品编码',
            prop: 'partNo',
            search: true
          },
          {
            label: '产品名称',
            prop: 'partName'
          },
          {
            label: 'BOM版本',
            prop: 'bomVersion'
          },
          {
            label: '派工产线',
            prop: 'productionLineName'
          },
          {
            label: '计划开始时间',
            prop: 'planStartDate'
          },
          {
            label: '计划结束时间',
            prop: 'planEndDate'
          },
          {
            label: '制定人',
            prop: 'creatorName'
          },
          {
            label: '状态',
            prop: 'status',
            type: 'select',
            dicData: [
              {
                label: '待排程',
                value: 1
              },
              {
                label: '待生产',
                value: 2
              },
              {
                label: '生产中',
                value: 3
              },
              {
                label: '完工',
                value: 4
              },
              {
                label: '锁定',
                value: 5
              },
              {
                label: '强制完工',
                value: 6
              }
            ]
          },
          {
            label: '备注',
            prop: 'remark'
          }
        ]
      };
    },
    openFailureCommonModal() {
      this.$refs.commonModalTemplate.showModal();
      this.modalName = 'failureModal';
      this.tableOption = {
        modalTitle: '不良现象（双击进行选择）',
        url: '/api/mes-product/mro-dict/page?dictType=BAD_PHENOMENON',
        isPage: true,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '不良代码',
            prop: 'code',
            search: true
          },
          {
            label: '不良现象描述',
            prop: 'name'
          }
        ]
      };
    },

    getWorkOrderDetail(workOrderNo) {
      getWorkOrderDetail(workOrderNo, 'FAI').then((res) => {
        this.addForm.workshopId = this._get(res, 'data.data.workOrderVO.workshopId', '');
        this.addForm.workshopName = this._get(res, 'data.data.workOrderVO.workshopName', '');
        this.addForm.lotNo = this._get(res, 'data.data.workOrderVO.lotNo', '');
        this.documentNo = this._get(res, 'data.data.documentNo', '');
      });
    },
    addInapection() {
      this.$refs.addForm.validate((valid, done) => {
        if (valid) {
          this.addForm['documentType'] = 'FAI';
          let line = this._find(this.lineList, { id: this.addForm.lineId });
          this.addForm['lineName'] = line ? line.name : '';
          this.addForm['sendExamineType'] = 'MANUAL';
          if (this.documentNo) {
            let documentNos = this.documentNo.split(',');
            this.$confirm(`该工单目前已存在${documentNos.length}个待检单（${this.documentNo}），是否继续报检?`, {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              add(this.addForm).then(
                (res) => {
                  this.addDialog = false;
                  this.$message.success(res.data.msg);
                  this.onLoad(this.page);
                  done();
                },
                (error) => {
                  done();
                }
              );
            });
          } else {
            add(this.addForm).then(
              (res) => {
                this.addDialog = false;
                this.$message.success(res.data.msg);
                this.onLoad(this.page);
                done();
              },
              (error) => {
                done();
              }
            );
          }
        }
      });
    },
    addClose(done) {
      this.$refs.addForm.resetFields();
      this.addForm = {};
      done();
    },
    /**
     * 上传前方法
     */
    pictureUploadBefore(file) {
      console.log(file);
      if (file.name.split('.')[1] != 'png' && file.name.split('.')[1] != 'jpeg' && file.name.split('.')[1] != 'jpg') {
        this.$message({
          type: 'warning',
          message: '只能上传png/jpeg/jpg文件！'
        });
        return false;
      }
    },
    pictureUploadSuccess(res) {
      // this.abnormalForm.attachments = res.data.link;
      if (this.abnormalForm['attachments'] === null) {
        this.abnormalForm['attachments'] = [];
      }
      this.abnormalForm['attachments'].push({
        attachmentId: res.data.attachId,
        link: res.data.link,
        attachmentName: res.data.originalName,
        attachmentType: 'INSPECTION'
      });
      console.log(this.abnormalForm['attachments']);
    },
    abnormalSubmit(type) {
      this.$refs.abnormalForm.validate((valid, done) => {
        if (valid) {
          let obj = {
            faultDescription: this.abnormalForm.faultDescription,
            improvementMeasure: this.abnormalForm.improvementMeasure,
            remark: this.abnormalForm.remark,
            qmsInspectionAttachmentList: [],
            qmsInspectionExceptionDetailList: []
          };
          let mainTypeObj = this._find(this.mainTypeList, { id: this.abnormalForm.mainType });
          obj.qmsInspectionExceptionDetailList = [];
          obj.qmsInspectionExceptionDetailList.push(
            {
              dictType: 'FAILURE',
              dictId: this.abnormalForm.failureId,
              dictCode: this.abnormalForm.failureCode,
              dictName: this.abnormalForm.failureName,
              remark: this.abnormalForm.remark
            },
            {
              dictType: 'CAUSE',
              subType: 'MAIN',
              dictId: mainTypeObj ? mainTypeObj.id : '',
              dictCode: mainTypeObj ? mainTypeObj.code : '',
              dictName: mainTypeObj ? mainTypeObj.name : '',
              remark: this.abnormalForm.remark
            }
          );
          console.log(obj.qmsInspectionExceptionDetailList);
          if (this.abnormalForm.subType.length > 0) {
            this._forEach(this.abnormalForm.subType, (item) => {
              let subTypeObj = this._find(this.subTypeList, { id: item });
              obj.qmsInspectionExceptionDetailList.push({
                dictType: 'CAUSE',
                subType: 'SUB',
                dictId: subTypeObj ? subTypeObj.id : '',
                dictCode: subTypeObj ? subTypeObj.code : '',
                dictName: subTypeObj ? subTypeObj.name : '',
                remark: this.abnormalForm.remark
              });
            });
          }
          obj.qmsInspectionAttachmentList = this.abnormalForm['attachments'];
          console.log(obj);
          obj['ngFailureName'] = this.abnormalForm.failureName;
          console.log(mainTypeObj);
          obj['ngMainCauseName'] = mainTypeObj.name;
          let subType = [];
          this._forEach(obj.qmsInspectionExceptionDetailList, (item) => {
            if (item.subType === 'SUB') {
              subType.push(item.dictName);
            }
          });
          obj['ngSubCauseName'] = subType.join(',');
          if (type === 'add') {
            this.abnormalRecordData.push(obj);
          } else {
            this.abnormalRecordData.splice(this.abnormalRecordIndex, 1, obj);
          }
          console.log(this.abnormalRecordIndex, this.abnormalRecordData);
          this.addAbnormalDialog = false;
          done();
        }
      });
    },
    addAbnormalDialogClose(done) {
      this.$refs.abnormalForm.resetFields();
      this.abnormalForm = {};
      this.pictureList = [];
      this.$refs.inspectionResultsRecordForm.resetFields();
      this.inspectionPictureList = [];
      done();
    },
    inspectionUploadSuccess(res) {
      console.log(this.inspectionResultsRecordForm);
      if (this.inspectionResultsRecordForm['attachments'] === null) {
        this.inspectionResultsRecordForm['attachments'] = [];
      }
      this.inspectionResultsRecordForm['attachments'].push({
        attachmentId: res.data.attachId,
        link: res.data.link,
        attachmentName: res.data.originalName,
        attachmentType: 'INSPECTION'
      });
      console.log(this.inspectionResultsRecordForm['attachments']);
    },
    handleSubmit(status) {
      this.$refs.inspectionResultsRecordForm.validate((valid, done) => {
        if (valid) {
          let params = {
            ...this.basicInfoForm,
            ...this.inspectionResultsRecordForm,
            status: status,
            qmsInspectionAttachmentList: this.inspectionResultsRecordForm['attachments'],
            qmsInspectionExceptionVoList: this.abnormalRecordData
          };
          console.log(params);
          handle(params).then(
            (res) => {
              this.handleDialog = false;
              this.$message.success(res.data.msg);
              this.onLoad(this.page);
              done();
            },
            (error) => {
              done();
            }
          );
        }
      });
    },
    abnormalRecordRowUpdate(row, type) {
      console.log(row);
      this.addAbnormalDialog = true;
      if (type === 'edit') {
        this.abnormalRecordIndex = row.$index;
        this.addAbnormalDialogTitle = '编辑异常记录';
        this.$nextTick(() => {
          this.$refs.abnormalForm.allDisabled = false;
        });
      } else {
        this.addAbnormalDialogTitle = '查看异常记录';
        this.$nextTick(() => {
          this.$refs.abnormalForm.allDisabled = true;
        });
      }
      this.abnormalForm = row;
      this.abnormalForm.subType = [];
      this._forEach(row.qmsInspectionExceptionDetailList, (item) => {
        if (item.dictType === 'FAILURE') {
          this.abnormalForm.failureId = item.dictId;
          this.abnormalForm.failureCode = item.dictCode;
          this.abnormalForm.failureName = item.dictName;
        } else {
          if (item.subType === 'MAIN') {
            this.abnormalForm.mainType = item.dictId;
          } else {
            this.abnormalForm.subType.push(item.dictId);
          }
        }
      });
      this.pictureList = [];
      this.abnormalForm.attachments = this._map(row.qmsInspectionAttachmentList, (item) => {
        this.pictureList.push({
          name: item.attachmentName,
          url: item.link
        });
        return {
          attachmentId: item.attachmentId,
          link: item.link,
          attachmentName: item.attachmentName,
          attachmentType: 'INSPECTION'
        };
      });
    },
    abnormalRecordDel(index) {
      this.abnormalRecordData.splice(index, 1);
    },
    inspectionRemoveFile(file, fileList) {
      console.log(file, this.inspectionResultsRecordForm.attachments);
      let url = this._get(file, 'response.data.link', '');
      let obj = this._find(this.inspectionResultsRecordForm.attachments, { link: url ? url : file.url });
      let index = this._findIndex(this.inspectionResultsRecordForm.attachments, obj);
      this.inspectionResultsRecordForm.attachments.splice(index, 1);
    },
    handleFullScreen() {
      this.fullScreen = !this.fullScreen;
    },

    getFileType(url) {
      // 从URL中提取文件名
      const filename = url.split('/').pop();
      // 提取文件名的扩展名
      const fileExtension = filename.split('.').pop();
      return fileExtension;
    },
    handlePreview(file) {
      let url = this._get(file, 'response.data.link', '');
      if (url) {
        file.url = url;
      }
      const fileType = this.getFileType(file.url);
      if (['doc', 'docx', 'xlsx', 'xls'].includes(fileType)) {
        this.previewVisible = true;
        this.fileUrl = file.url;
        this.fileType = fileType;
        return;
      }
      if (file.url.indexOf('pdf') != -1) {
        downLoad({ link: file.url }).then(
          (res) => {
            let fileURL = null;
            var blob = new Blob([res.data], { type: 'application/pdf' });
            if (window.createObjectURL != undefined) {
              // basic
              fileURL = window.createObjectURL(blob);
            } else if (window.webkitURL != undefined) {
              // webkit or chrome
              try {
                fileURL = window.webkitURL.createObjectURL(blob);
              } catch (error) {
                console.log(error);
              }
            } else if (window.URL != undefined) {
              // mozilla(firefox)
              try {
                fileURL = window.URL.createObjectURL(blob);
              } catch (error) {
                console.log(error);
              }
            }
            this.pdfUrl = '/pdf/web/viewer.html?file=' + encodeURIComponent(fileURL);
            this.showEsopDialog = true;
          },
          (error) => {}
        );
      } else {
        if (this.isImageFile(url || file.url)) {
          this.$ImagePreview([{ url: url ? url : file.url }], 0, {
            closeOnClickModal: false
          });
        } else {
          window.open(url || file.url);
        }
      }
    },
    isImageFile(filename) {
      let ext = filename.split('.').pop().toLowerCase();
      return ['jpg', 'jpeg', 'png', 'gif', 'bmp'].includes(ext);
    },
    pictureRemoveFile(file) {
      console.log(file, this.abnormalForm.attachments);
      let url = this._get(file, 'response.data.link', '');
      let obj = this._find(this.abnormalForm.attachments, { link: url ? url : file.url });
      let index = this._findIndex(this.abnormalForm.attachments, obj);
      this.abnormalForm.attachments.splice(index, 1);
    },
    handleExport() {
      // this.exportData = this.data;
      // this.exprotVisible = true;
      this.exportParams = Object.assign(filterEmptyValues(this.query), { statusStr: '2,3,5,6', documentType: 'IPQC' });
      this.$refs.exportComp.visible = true;
    },
    handleSelectData(val) {
      let current = 1;
      let pageSize = this.page.pageSize;
      if (val === 'all') {
        // 接口返回上限500条数据
        pageSize = 500;
      } else {
        current = this.page.currentPage;
      }
      this.btnLoading = true;
      getList(current, pageSize, Object.assign({ type: 'PART', ...this.query })).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.exportData = data.records;
        this.btnLoading = false;
      });
    },
    exportHandleClose(val) {
      this.exprotVisible = false;
      this.data = this.exportData.splice(0, this.page.pageSize);
    },
    openUserCommonModal() {
      this.modalName = 'userModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择检验人员信息（双击进行选择）',
        url: '/api/blade-system/user/page',
        isPage: true,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '用户姓名',
            prop: 'realName',
            search: true,
            searchLabelWidth: 150,
            searchSpan: 8
          },
          {
            label: '所属部门',
            prop: 'deptName',
            searchLabelWidth: 150,
            searchSpan: 8
          },
          {
            label: '职务',
            prop: 'postName'
          },
          {
            label: '用户平台',
            prop: 'userTypeName'
          }
        ]
      };
    },
    // 历史首件记录查询
    queryHistroyCheckRecords() {
      this.handleDialog = false;
      this.$set(this.query, 'partNo', this.basicInfoForm.partNo);
      this.page.currentPage = 1;
      this.onLoad(this.page);
    },
    handleSecondTimeInspection() {
      if (this.selectionList.length === 0) {
        this.$message.warning('请选择至少一条数据');
        return;
      }
      this.$confirm('二次检，会自动生成一张关联的制程巡检待检单，是否继续？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          return secondTimeInspection(this.selectionList[0].id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: 'success',
            message: '操作成功!'
          });
        });
    },
    openCommon(type) {
      if (type == 'partNo') {
        this.modalName = 'partNoModal';
        this.$refs.commonModalTemplate.showModal();
        this.tableOption = {
          modalTitle: '物料数据（双击进行选择）',
          url: '/api/mes-admin/part-master/page?semifinished=true',
          isPage: true,
          rowSelectionType: 'single',
          columnDefs: [
            {
              label: '物料编码',
              prop: 'partNo',
              search: true
            },
            {
              label: '物料名称',
              prop: 'name',
              search: true
            },
            {
              label: '产品型号',
              prop: 'partModel'
            }
          ]
        };
      } else if (type == 'sourceNo') {
        this.$refs.commonModalTemplate.showModal();
        this.modalName = 'sourceNoModal';
        this.tableOption = {
          modalTitle: '选择工单号（双击进行选择）',
          url: '/api/mes-product/work-order/page?workOrderStatus=2,3',
          isPage: true,
          rowSelectionType: 'single',
          columnDefs: [
            {
              label: '生产订单',
              prop: 'productionOrderNo',
              search: true
            },
            {
              label: '生产工单',
              prop: 'orderNo',
              search: true
            },
            {
              label: '工单类型',
              prop: 'orderType',
              type: 'select',
              dicUrl: '/api/blade-system/dict/dictionary?code=order_type',
              props: {
                label: 'dictValue',
                value: 'dictKey'
              }
            },
            {
              label: '工单数量',
              prop: 'planQuantity'
            },
            {
              label: '产品编码',
              prop: 'partNo',
              search: true
            },
            {
              label: '产品名称',
              prop: 'partName'
            },
            {
              label: 'BOM版本',
              prop: 'bomVersion'
            },
            {
              label: '派工产线',
              prop: 'productionLineName'
            },
            {
              label: '计划开始时间',
              prop: 'planStartDate'
            },
            {
              label: '计划结束时间',
              prop: 'planEndDate'
            },
            {
              label: '制定人',
              prop: 'creatorName'
            },
            {
              label: '状态',
              prop: 'status',
              type: 'select',
              dicData: [
                {
                  label: '待排程',
                  value: 1
                },
                {
                  label: '待生产',
                  value: 2
                },
                {
                  label: '生产中',
                  value: 3
                },
                {
                  label: '完工',
                  value: 4
                },
                {
                  label: '锁定',
                  value: 5
                },
                {
                  label: '强制完工',
                  value: 6
                }
              ]
            },
            {
              label: '备注',
              prop: 'remark'
            }
          ]
        };
      } else if (type == 'documentNo') {
        this.modalName = 'documentNoModel';
        this.$refs.commonModalTemplate.showModal();
        this.tableOption = {
          modalTitle: '选择检验单号（双击进行选择）',
          url: '/api/mes-product/qms-inspection-document/page?statusStr=2,3,5,6&documentType=IPQC',
          isPage: true,
          index: true,
          indexLabel: '序号',
          selection: true,
          rowSelectionType: 'single',
          columnDefs: [
            {
              label: '检验单号',
              prop: 'documentNo',
              search: true
            },
            {
              label: '生产工单',
              prop: 'sourceNo'
            },
            {
              label: '客户名称',
              prop: 'partnerName'
            },
            {
              label: '物料编码',
              prop: 'partNo'
            },
            {
              label: '物料名称',
              prop: 'partName'
            },
            {
              label: '产品型号',
              prop: 'partModel'
            }
          ]
        };
      }
    },
    /**
     * 选择模态框行数据
     */
    getSelectedRows(rowData) {
      switch (this.modalName) {
        case 'partNoModal':
          this.$set(this.query, 'partNo', this._get(rowData, 'partNo', ''));
          break;
        case 'failureModal':
          this.abnormalForm.failureId = rowData.id;
          this.abnormalForm.failureCode = rowData.code;
          this.abnormalForm.failureName = rowData.name;
          break;
        case 'sourceNoModal':
          this.$set(this.query, 'sourceNo', this._get(rowData, 'orderNo', ''));
          break;
        case 'documentNoModel':
          this.$set(this.query, 'documentNo', this._get(rowData, 'documentNo', ''));
          break;
        case 'workOrderModal':
          this.addForm.sourceId = rowData.id;
          this.addForm.sourceNo = rowData.orderNo;
          this.addForm.workOrderQuantity = rowData.planQuantity;
          this.addForm.partnerName = rowData.partnerName;
          this.addForm.partMasterId = rowData.partMasterId;
          this.addForm.partNo = rowData.partNo;
          this.addForm.partName = rowData.partName;
          this.addForm.partModel = rowData.partModel;
          this.getWorkOrderDetail(rowData.orderNo);
          break;
        case 'userModal':
          this.basicInfoForm.examineBy = rowData.id;
          this.basicInfoForm.examineByName = rowData.realName;
          break;
        default:
          break;
      }
    }
  }
};
</script>
<style lang="scss" scoped>
::v-deep .processInspectionRecord {
  .el-dialog__body {
    padding-top: 10px;
    .titleIcon {
      display: flex;
      align-items: center;
      margin: 5px 0;
      &.flex {
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
      .title {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0;
      }
      .name {
        font-weight: bold;
      }
    }
  }
}
.dialog-title {
  position: relative;
  .title {
    display: inline-block;
  }
  .fullscreen-icon {
    position: absolute;
    right: 20px;
    cursor: pointer;
    display: inline-block;
    font-size: 14px;
    color: #909399;
    &:hover {
      color: #0a84ff;
    }
  }
}

.fullscreen {
  ::v-deep .el-dialog {
    width: 100%;
    margin: 0 !important;
    margin-top: 0vh !important;
  }
}
.no_fullScreen {
  ::v-deep.el-dialog {
    width: 50%;
    margin-top: 5vh !important;
  }
}
</style>
